/*
package com.springboot.manager.controller;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import com.springboot.manager.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

*/
/**
 * 接入中心-登录管理
 *//*

@RestController
@RequestMapping("/login")

public class LoginController extends BaseController {

    @Value("${sa-token.tokenTime}")
    public long tokenTime;

    @Autowired
    private IUserService userService;

    @Resource
    private RedisService redisService;

    */
/**
     * 登录管理-登录
     *//*

    @PostMapping(value = "/login")
    public CommonResult login(String account, String password) {
        try {
            CommonResult commonResult = new CommonResult(ResultCodeEnum.FAILURE.getCode(), ResultCodeEnum.FAILURE.getMsg());
            log.info("account: " + account + " ~ password: " + password);
            commonResult = userService.getUserByAccountAndPwd(account, password);
            if (commonResult.getCode() == ResultCodeEnum.SUCCESS.getCode()) {
                UserInfo userInfo = JSONObject.parseObject(JSONObject.toJSONString(commonResult.getData()), UserInfo.class);
                userInfo.setPassword("");
                String tokenValue = "";
                //判断当前用户是否已经登录
                if (redisService.hasKey("userId:" + userInfo.getId())) {
                    //续签当前token
                    StpUtil.updateLastActivityToNow();
                    //续签redis
                    tokenValue = redisService.get("userId:" + userInfo.getId()).toString();
                } else {
                    StpUtil.login(userInfo.getId());
                    SaTokenInfo saTokenInfo = StpUtil.getTokenInfo();
                    tokenValue = saTokenInfo.getTokenValue();
                }
                redisService.set("token:" + tokenValue, userInfo, tokenTime);
                redisService.set("userId:" + userInfo.getId(), tokenValue, tokenTime);
                userInfo.setTokenValue(tokenValue);
                commonResult.setData(userInfo);
            }
            log.info("请求成功");
            return commonResult;
        } finally {
            System.out.println("---------------");
        }
    }

    */
/**
     * 登录管理-登出
     *
     * @param tokenValue
     * @return
     *//*

    @PostMapping("/logout")
    public CommonResult logOut(String tokenValue) {
        CommonResult<Object> commonResult = new CommonResult<>(ResultCodeEnum.FAILURE.getCode());
        StpUtil.logoutByTokenValue(tokenValue);
        //判断用户是否已经登录，如登录，清除redis
        if (ObjectUtil.isNotNull(redisService.get("token:" + tokenValue))) {
            User user = (User) redisService.get("token:" + tokenValue);
            redisService.remove("userId:" + user.getId());
        }
        redisService.remove("token:" + tokenValue);
        commonResult.setCode(ResultCodeEnum.SUCCESS.getCode());
        commonResult.setMessage("登出成功");
        return commonResult;
    }

    */
/**
     * 登录管理-根据token获取登录用户
     *
     * @param tokenValue
     * @return
     *//*

    @PostMapping("/loginByTokenValue")
    public CommonResult loginByTokenValue(String tokenValue) {
        CommonResult<Object> commonResult = new CommonResult<>(ResultCodeEnum.FAILURE.getCode());
        User user = (User) redisService.get(tokenValue);
        if (ObjectUtil.isNotNull(user)) {
            //续签当前token
            StpUtil.updateLastActivityToNow();
            //续约redis
            redisService.set(tokenValue, user, tokenTime);
            commonResult.setCode(ResultCodeEnum.SUCCESS.getCode());
            commonResult.setMessage("登录成功");
        } else {
            commonResult.setMessage("登录失败");
        }
        return commonResult;
    }

    */
/**
     * 登录管理-查询token剩余有效期
     *
     * @return
     *//*

    @GetMapping("/getTokenTimeout")
    public CommonResult getTokenTimeout() {
        long timeout = StpUtil.getTokenTimeout();
        return new CommonResult(200, "token剩余有效期: ", timeout);
    }

    */
/**
     * 登录管理-token[临时过期]剩余有效时间
     *
     * @return
     *//*

    @PostMapping("/getTokenActivityTimeout")
    public CommonResult getTokenActivityTimeout() {
        long timeout = StpUtil.getTokenActivityTimeout();
        return new CommonResult(200, "token[临时过期]剩余有效时间: ", timeout);
    }

    */
/**
     * 登录管理-判断是否登录
     *
     * @return
     *//*

    @GetMapping("/isLogin")
    public CommonResult isLogin() {
        boolean isLogin = StpUtil.isLogin();
        return new CommonResult(200, "是否登录: ", isLogin);
    }

}
*/
